/**
 * Implementation of a generic type object. The type is represented 
 * by the type expression: T(t1, ...,tn).  An attribute size was added for compiler
 * needs. 
 */
public class Type {
	 protected TypeExp _type_expression;
	 protected int _size;
	 /**
	  * Constructor for a simple type name().If not modified, the type expression
	  * term denotes a constant type. See addSubType for modifications
	  */
    public Type(String name, int size){
			_size = size;
			_type_expression = new TypeExp(name);
    }
	 /**
	  * Returns the type expression
	  */
	 public TypeExp typeExpression(){
		  return _type_expression;
	 }
	 /**
	  * Returns the size in bytes.
	  */
	 public int getSize(){
		  return _size;
    }
    /**
	  * Add a subtype to the type expression.
	  * During the compilation process it is not always possible or convenient
	  * to build a type in one operation. The addSubType method provides the way 
	  * to modify the type expression by increasing the arity of the top term with
	  * a new subterm. Formaly, the transformation is as follows:
	  * <p>
	  * name(t1, ...,tn), t(n+1) -> name(t1, ...,tn, t(n+1)) 
	  */
	 public void addSubType(Type t){
		  _type_expression.addSubType(t);
	 }
	 /**
	  * Test if two type expressions are EQUAL. Equality of two type expressions 
	  * is defined recursively: equality of names && same arity && equality of subterms
	  */
    public boolean isCompatible(Type t){
		  return _type_expression.isCompatible(t.typeExpression());
	 }
	 /**
	  * Returns a printable representation of the type expression.
	  */
	public String toString(){
		return _type_expression.toString();
	}
}
